<?php

    session_start();
    //header('Content-type: text/html; charset=utf-8');

    $error = 0;
    $errormessage = '';

    $data = '';

    if (!empty($_SESSION['user_id'])) {
        $user_id = $_SESSION['user_id'];
        $title = $_POST['title'];
        $categoryid = $_POST['categoryid'];
        $description = $_POST['description'];
        $filename = $_POST['filename'];
        $latitude = $_POST['latitude'];
        $longitude = $_POST['longitude'];
        $date = $_POST['date'];
        $tags = $_POST['tags'];

        $connection = mysql_connect ('localhost', 'zorik_if039', '9731')
        or die ('Unable to connect!');
        mysql_select_db('zorik_if039') or die (mysql_error());
        mysql_query("set character_set_client='utf8'"); 
        mysql_query("set character_set_server='utf8'"); 
        mysql_query("set character_set_results='utf8'"); 
        mysql_query("set collation_connection='utf8_unicode_ci'");

        $query3 = "INSERT INTO photo (user_id, categoryid, description, filename, latitude, longitude, tags, title, date)
                  VALUES ('$user_id', '$categoryid', '$description', '$filename', '$latitude', '$longitude', '$tags', '$title', '$date')";
        $result = mysql_query($query3) or die(mysql_error());;
        $data['uploaded'] = true;
    } else {
      $error = 1;
      $errormessage = 'User not logged';
      $data['uploaded'] = false;
    }
    $ajaxresult = (object) array('error' => $error, 'errormessage' => $errormessage, 'data' => $data);
    echo json_encode($ajaxresult);

?>